package game.block.entity;

import game.block.Constants;
import game.block.tile.Tile;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;

public abstract class Entity implements Constants {

    protected boolean exists;
    protected Sprite sprite;
    protected Tile currentTile;
    protected Vector2 position;
    protected float scale;
    protected boolean hideSprite;
    protected float direction;
    protected String info;

    public Entity(Vector2 pos, Tile tile, String path) {
        position = pos;
        currentTile = tile;
        if(path !=null){
        	this.sprite = new Sprite(new Texture(Gdx.files.internal(path)));
        }
        exists = true;
        hideSprite = false;
        scale = 1;
        direction=0;
        info="default";
        setInfo();
    }
    
    public abstract void setInfo();
    
    public String getInfo(){
    	return info;
    }

    public abstract void update(float delta);

    public void render(SpriteBatch sb) {
        if (!hideSprite && sprite!=null) {
            sb.draw(sprite.getTexture(), position.x - TILE_SIZE * 2 + 8, position.y - TILE_SIZE * 2 + 8, TILE_SIZE * 2, TILE_SIZE * 2, sprite
                    .getWidth(), sprite.getHeight(), SCALE*scale, SCALE*scale, direction, 0, 0, (int) sprite.getWidth(), (int) sprite.getHeight(), false, false);
        }
    }
    
    public void render(SpriteBatch sb, TextureRegion tr) {
        if (!hideSprite && sprite!=null) {
            sb.draw(tr, position.x - TILE_SIZE * 2 + 8, position.y - TILE_SIZE * 2 + 8, TILE_SIZE * 2, TILE_SIZE * 2, tr.getRegionWidth(), tr.getRegionHeight(), SCALE*scale, SCALE*scale, direction);
        }
    }
    
    public void dispose(){
    	sprite.getTexture().dispose();
    }

    public void delete() {
        exists = false;
    }

    public void revive() {
        exists = true;
    }

    public boolean isExists() {
        return exists;
    }

    public void setExists(boolean exists) {
        this.exists = exists;
    }

    public Vector2 getPosition() {
        return position;
    }

    public void setPosition(Vector2 position) {
        this.position = position;
    }

    public float getDirection() {
        return direction;
    }

    public void setDirection(float direction) {
        this.direction = direction;
    }

    public Tile getCurrentTile() {
        return currentTile;
    }

    public void setCurrentTile(Tile currentTile) {
        this.currentTile = currentTile;
    }

    public Sprite getSprite() {
        return sprite;
    }

    public void setSprite(Sprite sprite) {
        this.sprite = sprite;
    }

    public float getScale() {
        return scale;
    }

    public void setScale(float scale) {
        this.scale = scale;
    }

    public void hideSprite() {
        hideSprite=true;
    }
    
    public void unhideSprite(){
        hideSprite=false;
    }

}
